//
// Created by csp18 on 2025/2/26.
//

#include <iostream>

#include "NetAdapter.h"
#include "INetListener.h"

using namespace std;

void device_handler(unsigned char *user, const struct pcap_pkthdr *header, const unsigned char *pkt_data);

class MyListenter : public INetListener
{

public:
    void on_data_available(unsigned char *user,
                           const struct pcap_pkthdr *header,
                           const unsigned char *pkt_data)
    {

        printf("###############################################\n");

        printf("Packet captured:\n");

        printf("Timestamp: %ld.%ld seconds\n", header->ts.tv_sec, header->ts.tv_usec);

        printf("Packet length: %d bytes\n", header->len);

        for (int i = 0; i < header->len; i++)
        {
            printf("%02X ", pkt_data[i]);
        }
        printf("\n");

//        //以太网帧头
//        const unsigned char *data = pkt_data;
//        EthII_Hdr* eth_ii = eth_ii_parse(pkt_data);
//        eth_ii_print(eth_ii);
//        data += sizeof(EthII_Hdr);
//        switch (eth_ii->type)
//        {
//            case ETH_II_TYPE_ARP:
//                Arp_Hdr *arp = arp_parse(data);
//                arp_print(arp);
//                break;
//            default:
//                printf("Unknown packet type: %d\n", eth_ii->type);
//                break;
//        }
        printf("###############################################\n\n\n");
    }
};

int main()
{
    cout << "Network Tool" << endl;

    auto *listener = new MyListenter();
    NetAdapter m_NetAdapter;
    m_NetAdapter.NetDevsList();
    m_NetAdapter.openDev(NCID);
    m_NetAdapter.addListener(listener);
    //m_NetAdapter.run();

    cout << "Network Tool" << endl;

    return 0;
}
